<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Room_availableAction extends CommonAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        $roomid = '';
        if(!empty($key)) {
            $room_id = M('Room')->where("room_no like '%".$key."%'")->field('id')->findAll();
            $rooms = array();
            //TODO 检查其他的Action Filter，如果查询得到的ID只有一个，则不能使用in，需要判断
            if(count($room_id) >1 ) {
                foreach ($room_id as $k1 => $value) {
                    $rooms[$k1] = $value['id'];
                }
                $roomid = implode(",", $rooms);
                $map['room_id'] = array('in',$roomid);
            }else {
                $roomid = $room_id['0']['id'];
                $map['room_id'] = $roomid;
            }
        }
    }

   
    public function _before_add(){
         $this ->assign('hotel',M('Hotel')->where('status = 1')->field('name,id')->findAll());
    }
}
?>
